import { request } from '@/api/request';
import { HttpMethod } from '@/services/types';

/**
 * GET /comment/goods/:id 商品的评论列表
 * @param id
 * @param params
 * @param options
 */
export async function resGoodsCommentList(
  id: number,
  params: API.PaginationQueryBase,
  options?: { [key: string]: any }
) {
  return request<API.PaginationResult<API.CommentStruct>>(
    '/comment/goods/' + id,
    {
      method: HttpMethod.GET,
      params,
      ...(options || {}),
    }
  );
}

/**
 * GET /comment/my 我的评论
 * @param params
 * @param options
 */
export async function resMyCommentList(
  params: API.PaginationQueryBase & API.QueryGoodsComment,
  options?: { [key: string]: any }
) {
  return request<API.PaginationResult<API.CommentDetailStruct>>('/comment/my', {
    method: HttpMethod.GET,
    params,
    ...(options || {}),
  });
}

/**
 * GET /comment/goods 我出售商品的评论
 * @param params
 * @param options
 */
export async function resMyGoodsCommentList(
  params: API.PaginationQueryBase & API.QueryGoodsComment,
  options?: { [key: string]: any }
) {
  return request<API.PaginationResult<API.CommentDetailStruct>>(
    '/comment/goods',
    {
      method: HttpMethod.GET,
      params,
      ...(options || {}),
    }
  );
}

/**
 * GET /comment/detail/:id 评论详情
 * @param id
 * @param options
 */
export async function resGoodsCommentDetail(
  id: number,
  options?: { [key: string]: any }
) {
  return request<R<API.CommentDetailStruct>>('/comment/detail/' + id, {
    method: HttpMethod.GET,
    ...(options || {}),
  });
}

/**
 * PATCH /comment/reply/:id 回复评论
 * @param id
 * @param params
 * @param options
 */
export async function resReplyComment(
  id: number,
  params: API.ReplyDynamicParams,
  options?: { [key: string]: any }
) {
  return request<R<null>>('/comment/reply/' + id, {
    method: HttpMethod.PATCH,
    data: params,
    ...(options || {}),
  });
}

/*    admin    */

/**
 * Delete /admin/comment/:id 删除评论
 * @param id
 * @param options
 */
export async function resDeleteCommentAdmin(
  id: number,
  options?: { [key: string]: any }
) {
  return request<R<null>>('/admin/comment/' + id, {
    method: HttpMethod.DELETE,
    ...(options || {}),
  });
}

/**
 * GET /admin/comment 评论列表
 * @param params
 * @param options
 */
export async function resCommentListAdmin(
  params: API.QueryGoodsComment,
  options?: { [key: string]: any }
) {
  return request<R<API.PaginationResult<API.CommentDetailStruct>>>(
    '/admin/comment',
    {
      method: HttpMethod.GET,
      params,
      ...(options || {}),
    }
  );
}
